import http from "@/api";

export namespace Workshop {
  export interface WorkshopListItem {
    id: number;
    workshopCode: string;
    workshopName: string;
    factoryId: number;
    factoryName: string;
    workshopType: string;
    area: number;
    manager: string;
    phone: string;
    status: string;
    description: string;
    createdBy: string;
    createdTime: string;
    updatedBy: string;
    updatedTime: string;
    deleted: number;
  }

  export interface CreateWorkshopReq {
    workshopCode: string;
    workshopName: string;
    factoryId: number;
    workshopType: string;
    area?: number;
    manager?: string;
    phone?: string;
    description?: string;
  }

  export interface UpdateWorkshopReq {
    workshopName: string;
    factoryId: number;
    workshopType: string;
    area?: number;
    manager?: string;
    phone?: string;
    description?: string;
  }
}

/**
 * @name 车间管理模块
 */
// 获取车间列表
export const getWorkshopList = (params: any) => {
  return http.get<any>(`/workshops/page`, params);
};

// 根据ID获取车间详情
export const getWorkshopById = (id: number) => {
  return http.get<Workshop.WorkshopListItem>(`/workshops/${id}`);
};

// 根据工厂ID获取车间列表
export const getWorkshopByFactoryId = (factoryId: number) => {
  return http.get<Workshop.WorkshopListItem[]>(`/workshops/factory/${factoryId}`);
};

// 根据状态获取车间列表
export const getWorkshopByStatus = (params: any, status: string) => {
  return http.get<any>(`/workshops/status/${status}`, params);
};

// 创建车间
export const createWorkshop = (params: Workshop.CreateWorkshopReq) => {
  return http.post<number>(`/workshops`, params);
};

// 更新车间
export const updateWorkshop = (id: number, params: Workshop.UpdateWorkshopReq) => {
  return http.put(`/workshops/${id}`, params);
};

// 启用车间
export const enableWorkshop = (id: number) => {
  return http.post(`/workshops/${id}/enable`);
};

// 禁用车间
export const disableWorkshop = (id: number) => {
  return http.post(`/workshops/${id}/disable`);
};

// 设置车间为维护状态
export const setWorkshopMaintenance = (id: number) => {
  return http.post(`/workshops/${id}/maintenance`);
};

// 删除车间
export const deleteWorkshop = (id: number) => {
  return http.delete(`/workshops/${id}`);
};
